package com.vtc.session7;

import com.vtc.R;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.Toast;

public class MenuActivity extends Activity implements TabListener{

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.menu_activity);
		
		ActionBar actionBar = getActionBar();
		
		actionBar.addTab(actionBar.newTab().setText("Tab 1").setTabListener(this));
		actionBar.addTab(actionBar.newTab().setText("Tab 2").setTabListener(this));
		actionBar.addTab(actionBar.newTab().setText("Tab 3").setTabListener(this));
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
	}

	@Override
	public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
		// TODO Auto-generated method stub
		
	}

	@SuppressLint("NewApi")
	@Override
	public void onTabSelected(Tab tab, FragmentTransaction arg1) {
		// TODO Auto-generated method stub
		int position = tab.getPosition();
		switch(position){
		   case 0:
			   Tab1Frament tab1 = new Tab1Frament();
			   getFragmentManager().beginTransaction().replace(R.id.container, tab1).commit();
			   Toast.makeText(this, tab.getText(), Toast.LENGTH_LONG).show();
			   break;
		   case 1:
			   Tab2Frament tab2 = new Tab2Frament();
			   getFragmentManager().beginTransaction().replace(R.id.container, tab2).commit();
			   Toast.makeText(this, tab.getText(), Toast.LENGTH_LONG).show();
			   break;
		   case 2:
			   Toast.makeText(this, tab.getText(), Toast.LENGTH_LONG).show();
			   break;
		}
	}

	@Override
	public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
		// TODO Auto-generated method stub
		
	}
}
